import store from '@/store/store';
import axios from 'axios'
import router from '@/routes/route';
import { Message } from 'element-ui';
axios.defaults.baseURL = 'http://localhost:8080'
axios.defaults.timeout = 5000

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  if (response.data.code != 200) {
    if (response.data.code == 501) {
      Message.warning(response.data.msg)
      store.commit('user/logout')
      router.push('/')
      return Promise.reject()
    }
    if(response.data.code == 602) {
      router.replace({name:'404'})
      return Promise.reject()
    }
    Message.warning(response.data.msg)
    return Promise.reject()
  }
  return response;
}, function (error) {
  // 对响应错误做点什么
  Message.error("服务器开小差了!-.- ~")
  console.error(error);
  return new Promise(error)
});